-- strengthen2
-- create by panyl
-- 通用的强化属性类技能，绝对值

return {
    apply = function(source, target, skillId, round, para, extra)
        local effectRound = -1;
        extra = extra or {};
        local lastRound = extra.lastRound;


        if type(lastRound) == "number" then
            effectRound = round + lastRound + 1;
        elseif para[4] > 0 then
            -- 不包括本回合
            effectRound = round + para[4] + 1;
        end

        local prop = PropM.combine(source, "magic_last", skillId);
        effectRound = PropM.apply(prop, effectRound);
        prop = PropM.combine(source, "magic_last", "assist");
        effectRound = PropM.apply(prop, effectRound);

        -- 所有技能持续时间+
        prop = PropM.combine(source, "magic_last", "all");
        effectRound = PropM.apply(prop, effectRound);

        -- 1. 威力
        local force = para[3];
        -- 计算魔法效果加成
        local addon_rate = SkillM.calcMagicEffectAddon(source, skillId, true);
        -- 最终威力
        local force = math.modf(force * (addon_rate + 1000)/1000);

        -- 2. 魔力
        local magic = source:getMagic();

        -- 绝对值效果
        local v = math.modf(force *(magic + 3) / 1000);

        prop = { para[1], para[2], v, effectRound, };

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 记录属性
        PropM.recordBuff(target, prop);

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), arr[2], arr[3], tonumber(arr[4] or -1) };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 1. 威力
        local base = para[3];

        -- 计算魔法效果加成
        local addon_rate = SkillM.calcMagicEffectAddon(source, skillId, false);

        -- 最终威力
        local force = math.modf(base * (addon_rate + 1000)/1000);

        -- 2. 魔力
        local magic = source:getMagic();

        -- 效果/计算时魔力+3
        local vbase = math.modf(base * (magic + 3) / 1000);
        local vforce = math.modf(force * (magic + 3) / 1000);
        local vaddon = vforce - vbase;
        if vaddon == 0 then
            desc = string.gsub(desc, "{strengthen2}", vforce);
        else
            desc = string.gsub(desc, "{strengthen2}", vbase .. "(+" .. vaddon .. ")");
        end

        -- 回合数的显示
        local baseRound = para[4];
        local round = para[4];
        -- 增加持续时间的效果
        local prop = PropM.combine(source, "magic_last", skillId);
        round = PropM.apply(prop, round);
        prop = PropM.combine(source, "magic_last", "assist");
        round = PropM.apply(prop, round);
        prop = PropM.combine(source, "magic_last", "all");
        round = PropM.apply(prop, round);

        local addonRound = round - baseRound;
        if addonRound == 0 then
            desc = string.gsub(desc, "{round}", baseRound);
        else
            desc = string.gsub(desc, "{round}", baseRound .. "(+" .. addonRound .. ")");
        end

        -- 属性名称
        desc = string.gsub(desc, "{attrib}", FieldsM.getFieldName(para[2]));

        return desc;
    end,
};
